#pragma once
#include <vector>
#include <string>
#include <unordered_set>
#include "Node.h"

class Graph {

public :
	explicit Graph(std::vector<std::string> words);

    bool hasCircle();
    bool checkCircle(Node &node);
    int genAllChain(std::vector<std::string> &result);
    void dfsGenAll(std::vector<std::string> &result,Node &node);

    int genMaxWordChainWithCircle(std::vector<std::string> &result,char head, char tail);
    int genMaxWordChain(std::vector<std::string> &result,char head, char tail);
    void dfsGenMaxWordChain(Node &node, char tail);

    int genMaxCharChainWithCircle(std::vector<std::string> &result,char head, char tail);
    int genMaxCharChain(std::vector<std::string> &result,char head, char tail);
    void dfsGenMaxCharChain(Node &node, char tail);

    int genMaxWordChainNotSame(std::vector<std::string> &result);
    void dfsGenMaxWordChainNotSame(Node &node);
    int dfsGenMaxWordChainWithCircle(std::vector<std::string> &list,Node &node, char tail,std::unordered_set<std::string> &visited);

    int dfsGenMaxCharChainWithCircle(std::vector<std::string> &list,Node &node, char tail,std::unordered_set<std::string> &visited);


private:

    //a->0  index2nodes[head-'a'] 对应head开头的nodes
    std::vector< std::vector<Node> > index2nodes ;
};